package dto;

import java.sql.SQLException;

import daoInterface.CategoryDao;
import daoInterface.PurchaseDao;
import implementor.CategoryImp;
import implementor.PurchaseImp;

public class Material
{
/**
 * The attribute uniquely identify a material. It is generated each time a new
 * purchase is made.
 */
private String mCode;
/**
 * Refers to autoId of category
 */
private int catId;
/**
 * Stores the current quantity of material.
 * It is set first time to the value equal to purchase quantity.
 * It can be updated manually or can be updated when sell is made.
 */
private double mQuant;
/**
 * mrp of this material.It has nothing to with the actual sell price.
 * It is just for the display purpose.
 */
private double mMrp;
/**
 * Refers to the autoId of size.
 */
private int sizeId;
/**
 * Refers to autoId of color
 */
private int colorId;
/**
 * The quantity of material purchased by user initially from seller.
 * This does not change once the purchase has been made.
 */
private double purchaseQuant;
/**
 * The price at which purchase has been made it is 
 * saved as price per item
 */
private double purchasePrice;
/**
 * Reffers to purchase
 */
private int purchaseId;
/**
 * Logic not clear not implemented yet.
 */
private String taxCode;
// model attributes

/**
 * model attribue contains the color name and size name
 */
String modelcolorName,modelsizeName,modelcategoryname;

/**
 * model attribute contains the purchase object corresponding to the
 * purchase id
 */
Purchase modelPurchase;

/**
 * Zero argument constructor.Use this only and to set the attributes please
 * use gettter and setters
 */
public Material()
{
}
/**
 * Dto attributes constructor use this rarely as it is combersome to write
 */
public Material(String mCode,int id,double mQuant,double mMrp,int sizeId,int colorId,double purchaseQuant,double purchasePrice,int purchaseId,String taxCode)
{
this.mCode=mCode;
this.catId=id;
this.mQuant=mQuant;
this.mMrp=mMrp;
this.sizeId=sizeId;
this.colorId=colorId;
this.purchaseQuant=purchaseQuant;
this.purchasePrice=purchasePrice;
this.purchaseId=purchaseId;
this.taxCode=taxCode;
}

/************************************************************/
public void setmCode(String mCode)
{
this.mCode=mCode;
}


public String getmCode()
{
return mCode;
}

/************************************************************/
public void setCatId(int id)
{
this.catId=id;
}


public int getCatId()
{
return catId;
}

/************************************************************/
public void setmQuant(double mQuant)
{
this.mQuant=mQuant;
}


public double getmQuant()
{
return mQuant;
}

/************************************************************/
public void setmMrp(double mMrp)
{
this.mMrp=mMrp;
}


public double getmMrp()
{
return mMrp;
}

/************************************************************/
public void setsizeId(int sizeId)
{
this.sizeId=sizeId;
}


public int getsizeId()
{
return sizeId;
}

/************************************************************/
public void setcolorId(int colorId)
{
this.colorId=colorId;
}


public int getcolorId()
{
return colorId;
}

/************************************************************/
public void setpurchaseQuant(double purchaseQuant)
{
this.purchaseQuant=purchaseQuant;
}


public double getpurchaseQuant()
{
return purchaseQuant;
}

/************************************************************/
public void setpurchasePrice(double purchasePrice)
{
this.purchasePrice=purchasePrice;
}


public double getpurchasePrice()
{
return purchasePrice;
}

/************************************************************/
public void setpurchaseId(int purchaseId)
{
this.purchaseId=purchaseId;
}


public int getpurchaseId()
{
return purchaseId;
}

/************************************************************/
public void settaxCode(String taxCode)
{
this.taxCode=taxCode;
}


public String gettaxCode()
{
return taxCode;
}

/**
 * Sets the modelPurchase , it is necessary that before being called the the purchaseId
 * should be initialed.
 */
public void setmodelPurchase()
{
	PurchaseDao purchase = new PurchaseImp();
	try {
		purchase.retrieve("autoPurchaseId",this.purchaseId+"");
	} catch (SQLException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	} catch (Exception e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	
}
/**
 * Returns  the modelPurchase , it is necessary that before being called the the set modelPurchase]
 * must be called
 * @return 
 */
public Purchase getModelPurchase()
{
	return this.modelPurchase;
}

public String getCategoryname() {
	Category cat = null;
	CategoryDao imp = new CategoryImp();
	try {
		cat=imp.retrieve("autoId",this.catId+"");
	} catch (Exception e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	this.modelcategoryname=cat.getLeafName();
	return modelcategoryname;
}
public void setCategoryname(String categoryname) {
	this.modelcategoryname = categoryname;
}
public String getSizeName() {
	return modelsizeName;
}
public void setSizeName(String sizeName) {
	this.modelsizeName = sizeName;
}



}
